package org.vaadin.nf4v.core.navigation.event;

import org.vaadin.nf4v.core.navigation.NavigationRequest;

import java.io.Serializable;

/**
 * Navigation listener is used to listen for navigation request state change.
 * Global listener may be registered using NavigationManager.
 * Local listener may be registered through Navigator instance in current window.
 *
 * The same instance may be registered for more then one state, e.g.
 * if listener need to receive all not cancelled navigations to new pages:
 * NavigationManager.addApplicationNavigationListener(listener, NavigationState.PAGE_NAVIGATION, NavigationState.BEFORE_NAVIGATION)
 *
 * Or if listener need to perform some action after parameters change navigation:
 * NavigationManager.addApplicationNavigationListener(listener, NavigationState.PAGE_PARAMETERS_CHANGE, NavigationState.AFTER_NAVIGATION)
 *
 * etc..
 */
public interface NavigationListener extends Serializable {

    /**
     * Called on navigation request state change.
     * Listener can interrupt request using cancel() method of request.
     * Navigation request could not be cancelled on states: BEFORE_NAVIGATION and AFTER_NAVIGATION
     *
     * @param request navigation request
     */
    void onNavigation(NavigationRequest request);
}
